<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui" template="/mainTemplate.xhtml">

    <ui:define name="content">
        <h:form id="mechanismForm" >
            <p:growl id="msg" showDetail="true" sticky="true" />
            <p:toolbar id="mechanismToolbar" style="margin-top:20px; margin-bottom:5px">
                <p:toolbarGroup align="left">
                    <p:commandButton value="Добавить"
                                     action="#{mechanismsBean.addMechanism()}" style="font-size: 85% !important"/>
                    <p:commandButton value="Редактировать" update=":editMechanismDialogForm:editMechanismDialog, msg"
                                     action="#{mechanismsBean.edit()}" style="font-size: 85% !important"/>
                    <p:commandButton value="Работа техники"
                                     action="#{mechanismsBean.coming()}" style="font-size: 85% !important"/>

                </p:toolbarGroup>
            </p:toolbar>

            <p:dataTable id="mechanismTable" var="mechanism" value="#{mechanismsBean.equipmentsList}"
                         rowKey="#{mechanism.name}" selection="#{mechanismsBean.selectedMechanism}"
                         selectionMode="single">

                <p:column headerText="Наиминование">
                    <h:inputHidden value="#{mechanism.id}"/>#{mechanism.name}
                </p:column>
                <p:column headerText="Полное наиминование">
                    <h:inputHidden value="#{mechanism.id}"/>#{mechanism.name}
                </p:column>

                <p:column headerText="Описание">
                    #{mechanism.description}"
                </p:column>

            </p:dataTable>

        </h:form>

        <h:form id="addMechanismDialogForm">
            <p:dialog id="addMechanismDialog" widgetVar="addMechanismDialog" header="Добавление техники" modal="true">
                <ui:include src="dialogs/addMechanism.xhtml"/>
            </p:dialog>
            <script type="text/javascript">
                function handleAddMechanismRequest(xhr, status, args) {
                    if(args.validationFailed || !args.saveAdd) {
                        jQuery('#addMechanismDialog').effect("shake", { times:3 }, 100);
                    } else {
                        addMechanismDialog.hide();
                    }
                }
            </script>
        </h:form>
        <h:form id="editMechanismDialogForm">
            <p:dialog id="editMechanismDialog" widgetVar="editMechanismDialog" header="Редактирование техники" modal="true">
                <ui:include src="dialogs/editMechanism.xhtml"/>
            </p:dialog>
            <script type="text/javascript">
                function handleEditMechanismRequest(xhr, status, args) {
                    if(args.validationFailed || !args.saveEdit) {
                        jQuery('#editMechanismDialog').effect("shake", { times:3 }, 100);
                    } else {
                        editMechanismDialog.hide();
                    }
                }
            </script>
        </h:form>
        <h:form id="comingMechanismDialogForm">
            <p:dialog id="comingMechanismDialog" widgetVar="comingMechanismDialog" header="Работа техники" modal="true">
                <ui:include src="dialogs/comingMechanism.xhtml"/>
            </p:dialog>
            <script type="text/javascript">
                function handleComingMechanismRequest(xhr, status, args) {
                    if(args.validationFailed || !args.saveComing) {
                        jQuery('#comingMechanismDialog').effect("shake", { times:3 }, 100);
                    } else {
                        comingMechanismDialog.hide();
                    }
                }
            </script>
        </h:form>
    </ui:define>
</ui:composition>